<p>Mobile devices expose unique identifiers that can be used to identify users across applications or devices. These identifiers put user privacy at
risk, as they might allow the tracking of user activity without consent, while making it difficult or impossible for users to reset them.</p>
<p>Privacy violations can cause apps to be removed from app stores and can result in legal action or loss of trust from users.</p>
<h2>Ask Yourself Whether</h2>
<ul>
  <li> The identifier is used to track users between applications or devices. </li>
  <li> The identifier cannot be easily reset by the user. </li>
  <li> The identifier is connected to personally identifiable information. </li>
  <li> The identifier is linked to the device hardware (MAC address, IMEI, etc). </li>
</ul>
<p>There is a risk if you answer yes to any of these questions.</p>
<h2>Recommended Secure Coding Practices</h2>
<ul>
  <li> Whenever possible, use identifiers that users can easily reset. </li>
  <li> Don’t link identifiers to personally identifiable information without collecting users' explicit consent. </li>
  <li> Avoid using identifiers that are linked to the device hardware (MAC address, IMEI, etc). </li>
  <li> Only use the Advertising ID for user profiling or ads use cases. </li>
</ul>
<p>For ads use cases, use the Advertising ID provided by the platform. This identifier is designed to be reset by the user and has an associated
Personalized Ads flag.</p>
<p>For non-ads use cases, the most privacy-friendly identifiers that can be used are:</p>
<ul>
  <li> Firebase installation ID (FID) </li>
  <li> A privately stored GUID generated by the app </li>
</ul>
<h2>Sensitive Code Example</h2>
<pre data-diff-id="1" data-diff-type="noncompliant">
String uid = Settings.Secure.getString(contentResolver, Settings.Secure.ANDROID_ID); // Sensitive
User user = new User(
    uid,
    "John",
    "Doe",
);
</pre>
<h2>Compliant Solution</h2>
<pre data-diff-id="1" data-diff-type="compliant">
String uid = UUID.randomUUID().toString();
User user = new User(
    uid,
    "John",
    "Doe",
);
</pre>
<h2>See</h2>
<ul>
  <li> OWASP - <a href="https://owasp.org/www-project-mobile-top-10/2023-risks/m6-inadequate-privacy-controls">Mobile Top 10 2024 Category M6 -
  Inadequate Privacy Controls</a> </li>
  <li> CWE - <a href="https://cwe.mitre.org/data/definitions/213">CWE-213 - Exposure of Sensitive Information Due to Incompatible Policies</a> </li>
  <li> Android Documentation - <a href="https://developer.android.com/identity/user-data-ids">Best practices for unique identifiers</a> </li>
</ul>

